package com.accloud.cloudservice;

import com.accloud.common.ACConfiguration;
import com.accloud.service.ACDevice;
import com.accloud.service.ACDeviceActive;
import com.accloud.service.ACDeviceMgr;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;

public class ACDeviceManager extends ACBaseManager implements ACDeviceMgr {
    public ACDeviceManager() {
        super(ACConfiguration.WAREHOUSE_SERVICE_NAME, 1, false);
    }

    @Override // com.accloud.service.ACDeviceMgr
    public void activateDevice(String subDomain, ACDeviceActive deviceActive, VoidCallback callback) {
        ACMsg req = ACMsg.getACMsg(subDomain);
        req.setName("activateDevice");
        req.put("physicalDeviceId", deviceActive.getPhysicalDeviceId());
        req.put("devVersion", deviceActive.getDeviceVersion());
        if (deviceActive.getMac() != null) {
            req.put("mac", deviceActive.getMac());
        }
        if (deviceActive.getModuleVersion() != null) {
            req.put("modVersion", deviceActive.getModuleVersion());
        }
        if (deviceActive.getLatitude() != null) {
            req.put("latitude", deviceActive.getLatitude());
        }
        if (deviceActive.getLongitude() != null) {
            req.put("longitude", deviceActive.getLongitude());
        }
        sendReq(req, callback);
    }

    @Override // com.accloud.service.ACDeviceMgr
    public void getDeviceInfo(String subDomain, String physicalDeviceId, final PayloadCallback<ACDevice> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(subDomain);
        req.setName("getDeviceInfo");
        req.put("physicalDeviceId", physicalDeviceId);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACDeviceManager.AnonymousClass1 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACDevice(resp.getString("ipAddr"), resp.getString("devVersion"), resp.getString("modVersion"), resp.getString("activeTime"), resp.getString("lastOnlineTime"), resp.getString("country"), resp.getString("province"), resp.getString("city")));
            }
        });
    }
}
